const { webEnvironment } = require('../config/index')

function index(Joi) {
  this.path = '/:env?'
  return async ctx => {
    const env = ctx.params.env || 'dev'
    if (!webEnvironment[env]) {
      ctx.status = 404
      return
    }

    ctx.state = {
      title: process.env.APP_NAME,
      env
    }

    await ctx.render('index', ctx.state)
  }
}

module.exports = {
  index
}